package dao.impl;

import dao.UserDao;
import entity.Users;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import util.DateUtils;
import util.DbUtils;

import java.sql.SQLException;
import java.util.Date;

/**
 * User: key
 * ClassName:UserDaoImpl
 * Date: 2023/5/6
 * Time: 15:05
 * description:
 */
public class UserDaoImpl implements UserDao {
    private QueryRunner qr = new QueryRunner(DbUtils.getDataSource());
    @Override
    public Users getUser(String userCode) throws SQLException {
        return qr.query("select user_id 'userId',user_code 'userCode',password,email,gender,register_time 'registerTime',last_logintime 'lastLogintime' from users where user_code = ?",
                new BeanHandler<>(Users.class),userCode);
    }

    @Override
    public int addUser(Users u) throws SQLException {
        return qr.update("insert into users (user_code,password,email,gender,register_time) values (?,?,?,?,?)",
                u.getUserCode(),
                u.getPassword(),
                u.getEmail(),
                u.getGender(),
                u.getRegisterTime());
    }
}
